日本語
base_url
https://openrouter.ai/api/v1
import os import openai import weave # highlight-next-line weave.init('together-weave') system_content = "You are a travel agent. Be descriptive and helpful." user_content = "Tell me about San Francisco" # highlight-next-line client = openai.OpenAI( # highlight-next-line api_key=os.environ.get("OPENROUTER_API_KEY"), # highlight-next-line base_url="https://openrouter.ai/api/v1", # highlight-next-line ) chat_completion = client.chat.completions.create( extra_headers={ "HTTP-Referer": $YOUR_SITE_URL, # Optional, for including your app on openrouter.ai rankings. "X-Title": $YOUR_APP_NAME, # Optional. Shows in rankings on openrouter.ai. }, model="meta-llama/llama-3.1-8b-instruct:free", messages=[ {"role": "system", "content": system_content}, {"role": "user", "content": user_content}, ], temperature=0.7, max_tokens=1024, ) response = chat_completion.choices[0].message.content print("Model response:\n", response)
このページは役に立ちましたか?